﻿using System;
using System.Reflection;

namespace AttributeTest
{
    class VersionsInAction
    {
        [Version("FirstVersion")]
        public void FirstMethod()
        {
            Type type = typeof(VersionsInAction);
            MethodInfo[] allMethods = type.GetMethods();
            VersionAttribute myAttribute;
            myAttribute = Attribute.GetCustomAttribute(allMethods[0], typeof(VersionAttribute), false) as VersionAttribute;
            Console.WriteLine("This class name is {0}. \nComment :{1}", myAttribute.Name, myAttribute.Comment);
        }

        [Version("SecondVersion", "This is the second method")]
        public void SecondMethod()
        {
            Type type = typeof(VersionsInAction);
            MethodInfo[] allMethods = type.GetMethods();
            VersionAttribute myAttribute;
            myAttribute = Attribute.GetCustomAttribute(allMethods[1], typeof(VersionAttribute), false) as VersionAttribute;
            Console.WriteLine("This class name is {0}. \nComment :{1}", myAttribute.Name, myAttribute.Comment);
        }

        [Version("ThirdVersion", "This is the third method")]
        public void ThirdMethod()
        {
            Type type = typeof(VersionsInAction);
            MethodInfo[] allMethods = type.GetMethods();
            VersionAttribute myAttribute;
            myAttribute = Attribute.GetCustomAttribute(allMethods[2], typeof(VersionAttribute), false) as VersionAttribute;
            Console.WriteLine("This class name is {0}. \nComment :{1}", myAttribute.Name, myAttribute.Comment);
        }

        [Version("ForthVersion")]
        public void ForthMethod()
        {
            Type type = typeof(VersionsInAction);
            MethodInfo[] allMethods = type.GetMethods();
            VersionAttribute myAttribute;
            myAttribute = Attribute.GetCustomAttribute(allMethods[3], typeof(VersionAttribute), false) as VersionAttribute;
            Console.WriteLine("This class name is {0}. \nComment :{1}", myAttribute.Name, myAttribute.Comment);
        }
    }
}